/*
 * =====================================================================================
 *
 *       Filename:  dynctl.h
 *
 *    Description:  
 *
 *        Version:  1.0
 *        Created:  02/06/2018 04:37:40 PM
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  jianxi sun (jianxi), ycsunjane@gmail.com
 *   Organization:  
 *
 * =====================================================================================
 */
#ifndef __DYNCTL_H__
#define __DYNCTL_H__
#include <ev.h>
#include <ctype.h>
#include "buffer2.h"
#define TO_NEXT_WORD(s, e) do { \
	while (*s != '\0' && !isblank(*s)) { \
		s++; \
	} \
	if (*s != '\0') { \
		*s = '\0'; \
		s++; \
		while (isblank(*s)) \
			s++; \
	} else { \
		e = 1; \
	} \
} while (0)

struct dynctl;

typedef struct listen_ctx {
	struct ev_loop *loop;
	ev_io io;
	int fd;
} listen_ctx_t;

typedef struct dynctl_ctx {
	ev_io io;
	struct dynctl *dynctl;
} dynctl_ctx_t;

typedef struct dynctl {
	int fd;
	struct ev_loop *loop;

	buffer2_t *buf;
	struct dynctl_ctx *recv_ctx;
	struct dynctl_ctx *send_ctx;
	struct listen_ctx *listener;
} dynctl_t;

void accept_dynctl_cb(EV_P_ ev_io *w, int revents);

#endif /* __DYNCTL_H__ */
